#include <linux/init.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/irqdesc.h>
#include <linux/kernel.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");

#define IRQ_NUM 123

static int irq_enabled = 0;
static cpumask_t irq_affinity;

static irqreturn_t my_irq_handler(int irq, void *dev_id)
{
    pr_info("Interrupt received on IRQ %d\n", irq);
    return IRQ_HANDLED;
}

static int __init my_module_init(void)
{
    int ret;

    ret = request_irq(IRQ_NUM, my_irq_handler, IRQF_SHARED, "my_irq", NULL);
    if (ret < 0) {
        pr_err("Failed to request IRQ %d\n", IRQ_NUM);
        return ret;
    }

    pr_info("Successfully requested IRQ %d\n", IRQ_NUM);

    cpumask_set_cpu(0, &irq_affinity);
    cpumask_set_cpu(1, &irq_affinity);

    ret = irq_set_affinity_hint(IRQ_NUM, &irq_affinity);
    if (ret < 0) {
        pr_err("Failed to set affinity for IRQ %d\n", IRQ_NUM);
        return ret;
    }

    pr_info("Successfully set affinity for IRQ %d\n", IRQ_NUM);

    enable_irq(IRQ_NUM);
    irq_enabled = 1;
    pr_info("Enabled IRQ %d\n", IRQ_NUM);

    return 0;
}

static void __exit my_module_exit(void)
{
    if (irq_enabled) {
        disable_irq(IRQ_NUM);
        pr_info("Disabled IRQ %d\n", IRQ_NUM);
    }

    free_irq(IRQ_NUM, NULL);
    pr_info("Released IRQ %d\n", IRQ_NUM);
}

module_init(my_module_init);
module_exit(my_module_exit);

